var app = getApp(),
  $ = require("../../utils/httpHelper.js");
var address = require('../../utils/city.js')

Page({
  data: {
    username: '',
    phone: '',
    yzm: '',
    shenfencodestr: "",
    height: 0,
    shenfenjc: false,
    shenfencode: false,
    yzmjc: false,
    yzmstatus: false,
    showdialog:false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({ height: res.windowHeight })
      }
    })
    let par = {
      rd_session: app.globalData.userInfo.rd_session
    }
    $.httpPost("member_info", par, (data, err) => {
      if(data.data.data.name == null){
        return
      }else{
        this.setData({
          username: data.data.data.name,
          shenfencodestr: data.data.data.idcard,
          phone: data.data.data.phone
        })
      }
      
    })

  },

  formSubmit: function (e) {
    var rd_session = wx.getStorageSync('rd_session');
    let name = e.detail.value.username
    let phone = e.detail.value.phone
    let idcard = e.detail.value.shenfencodestr
    console.log(name)
    if (this.checkinfo(name,phone,idcard)) {
      let par = { rd_session: rd_session, name: name, idcard: idcard, phone: phone }
      $.httpPost("edit_member_info", par, (data, err) => {
        if (data.result == "success") {
          wx.switchTab({
            url: '/pages/mine/mine',
          })
          this.setData({
            showdialog: false
          })
        }
      })
    } else {
      wx.showToast({
        title: '不能是空',
      })
    }
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
  },
  formReset: function () {
    this.setData({
      showdialog: false
    })
    console.log('form发生了reset事件')
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  checkinfo(name, phone, shenfencodestr) {
    console.log(name, phone, shenfencodestr)
    if (app.check_empty(name) || app.check_empty(phone) || app.check_empty(shenfencodestr)) {
      console.log(false)
      return false
    } else {
      console.log(true)
      return true
    }
  },
  tj() {
    this.setData({
      showdialog:true
    })
    
  },
  toAddr(){
    wx.navigateTo({
      url: '/pages/address/addressli',
    })
  }

})
